package jjn.round2;

/**
 * @author Jiang Jining
 * @since 2023-06-26 23:20
 */
public class LeetCode2485_FindThePivotNumber {
    public int pivotInteger(int n) {
        if (n == 1) {
            return 1;
        }
        for (int i = 2; i <= n; i++) {
            int leftSum = i * (i - 1) / 2;
            int rightSum = (n + i + 1) * (n - i) / 2;
            if (leftSum == rightSum) {
                return i;
            }
            if (leftSum > rightSum) {
                break;
            }
        }
        return -1;
    }
}
